﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Events;

namespace BlueMarble.Genesis.Common.Home
{
    public class HomeViewModel: IHomeViewModel
    {
        public IHomeView View { get; set; }
        protected IRegionManager regionManager { get; set; }
        protected IUnityContainer container { get; set; }
        protected IEventAggregator eventAggregator { get; set; }

        public HomeViewModel(IHomeView view, IRegionManager regionManager, IUnityContainer container, IEventAggregator eventAggregator)
        {
            this.regionManager = regionManager;
            this.container = container;

            this.View = view;
            this.View.ViewModel = this;

            this.eventAggregator = eventAggregator;

            this.eventAggregator.GetEvent<BlueMarble.Genesis.Infrastructure.Events.Security.LoggedInEvent>().Subscribe(LoggedInEvent);
            this.eventAggregator.GetEvent<BlueMarble.Genesis.Infrastructure.Events.Security.LoggedOutEvent>().Subscribe(LoggedOutEvent);
            this.eventAggregator.GetEvent<BlueMarble.Genesis.Infrastructure.Events.Security.ValidUserEvent>().Subscribe(ValidUserEvent);
        }

        public void LoggedInEvent(bool LoggedIn)
        {
        }

        public void LoggedOutEvent(object UserObject)
        {
        }

        public void ValidUserEvent(bool ValidUser)
        {
        }

        public void Authenticate()
        {
            BlueMarble.Genesis.Infrastructure.Interfaces.IAuthenticationViewModel authenticationViewModel = container.Resolve<BlueMarble.Genesis.Infrastructure.Interfaces.IAuthenticationViewModel>();

            authenticationViewModel.Login("test", "@Alpha123");
        }
    }
}
